import { asyncRouterMap, constantRouterMap, employees, administrators } from '@/router'

const permission = {
  state: {
    routers: constantRouterMap,
    addRouters: [],
    routerLoadDone: false
  },
  mutations: {
    SET_ROUTERS: (state, routers) => {
      state.addRouters = routers
      state.routers = constantRouterMap.concat(routers)
      state.routerLoadDone = true;
    }
  },
  actions: {
    async generateRoutes({ commit }, isAdmin) {
      let accessedRouters = isAdmin ? [...administrators, ...asyncRouterMap] : [...employees, ...asyncRouterMap];
      commit('SET_ROUTERS', accessedRouters)
    }
  }
}

export default permission
